module equation_solver_type
    implicit none
    private

    public :: equation

    !定义类
    type :: equation
        integer         :: a
        integer         :: b
        real            :: result = 0        
    contains    

    !define function
        procedure,pass  ::  set_parameter
        procedure,pass  ::  remove_parameter
        procedure,pass  ::  calculate
        procedure,pass  ::  print_result
    endtype

contains

    subroutine set_parameter(this,a,b)
        class(equation) :: this
        integer         :: a
        integer         :: b    

        integer :: nerror
        nerror = 0
        
        if(a == 0) then
            write(*,*) "Error: para_a wrong"
            nerror = nerror + 1
        endif

        if( nerror == 0) then
            this%a = a
            this%b = b
        end if
    endsubroutine

    subroutine remove_parameter(this)
        class(equation) :: this

        this%a = 0
        this%b = 0

    endsubroutine

    subroutine calculate(this)
        class(equation) :: this
        !ax+b=0
        this%result = -this%b/this%a
    endsubroutine

    subroutine print_result(this)

        class(equation) :: this
        write(*,*) "the result of equation is",this%result

    endsubroutine
endmodule

